{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Episode 01-playlist: Let's build you a movie playlist.\n",
    "\n",
    "### PlayListFlow is a movie playlist generator, and this notebook shows how you can use the Metaflow client to access data from the versioned Metaflow runs. In this example,  you can view all the historical playlists."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import the metaflow client"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from metaflow import Flow, get_metadata\n",
    "print(\"Current metadata provider: %s\" % get_metadata())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Print your latest generated playlist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "run = Flow('PlayListFlow').latest_successful_run\n",
    "print(\"Using run: %s\" % str(run))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"Playlist generated on %s\\n\" % str(run.finished_at))\n",
    "print(\"Playlist for movies in genre '%s'\" % run.data.genre)\n",
    "for pick, movie in enumerate(run.data.playlist, start=1):\n",
    "    print(\"Pick %d: '%s'\" % (pick, movie))\n",
    "    if pick >= run.data.recommendations:\n",
    "        break\n",
    "                \n",
    "print(\"Bonus Pick: '%s' from '%s'\" % (run.data.bonus[0], run.data.bonus[1]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## See what the top pick was for previously generated playlists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for run in Flow('PlayListFlow').runs():\n",
    "    if run.successful:\n",
    "        print(\"Playlist generated on %s\" % run.finished_at)\n",
    "        print(\"Playlist for movies in genre '%s'\" % run.data.genre)\n",
    "        if run.data.playlist:\n",
    "            print(\"Top Pick: '%s'\" % run.data.playlist[0])\n",
    "        print('\\n')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
